import { defineStore } from 'pinia'

export interface PageParamsState {
  id: string, // 幻灯片集合ID
  isSameSource: boolean, // 是否是同源策略部署
  baseUrl?: string, // 项目地址
  template?: string, // 模板ID
}

export const usePageParamsStore = defineStore('pageParams', {
  state: (): PageParamsState => ({
    id: '', // 幻灯片集合ID
    baseUrl: '', // 项目地址
    template: '', // 模板ID
    isSameSource: false, // 是否是同源策略部署
  }),

  getters: {
    getPageParams(state) {
      return {...state}
    },
    getPageIdParam(state) {
      return state.id
    },
    getPageBaseUrlParam(state) {
      return state.baseUrl
    },
    getPageTemplateParam(state) {
      return state.template
    },
    getIsSameSourceParam(state) {
      return state.isSameSource
    },
  },

  actions: {
    setAllParams(params: PageParamsState) {
      this.id = params.id
      this.baseUrl = params.baseUrl
      this.template = params.template
    },
    setIdParams(val: string) {
      this.id = val
    },
    setBaseUrlParams(val: string) {
      this.baseUrl = val
    },
    setTemplateParams(val: string) {
      this.template = val
    },
    setIsSameSourceParams() {
      // if (window.parent) {
      //   this.isSameSource = true
      // }
      // else {
        
      // }
    }
  },
})